import os
import os.path as osp


def run(logfilename, min_conf, max_conf):
    outfilename = f'results-conf{min_conf}-{max_conf}.txt'

    with open(logfilename, 'r') as fp:
        lines = fp.readlines()
    print(len(lines))

    new_lines = []
    for line in lines:
        one_box_info = line.strip('\n').split(' ')
        # print(one_box_info)
        path_img, cls_name, conf, *xy4 = one_box_info
        if min_conf <= eval(conf) <= max_conf:
            new_lines.append(line)
    print(len(new_lines))

    with open(outfilename, 'w') as fp:
        for i in new_lines:
                fp.write(i)


if __name__ == '__main__':
    logfilename = 'results-conf0.1-best-BiCnnNew.txt'
    min_conf, max_conf = 0.5, 1.0
    run(logfilename, min_conf, max_conf)
